import ajaxMainTableData from './ajaxMainTableData';
import updateButtonStatus from "./updateButtonStatus";
import handleAllpks from "./handleAllpks";
import handlePK from "./handlePK";

export default function getMainTableData() {
    const {
        searchModalValue,
        orgVal,
        queryOid,
        pageInfo
    } = this.state;

    let postData = {
        querycondition: searchModalValue,
        pk_org: orgVal && orgVal.refpk,
        oid: queryOid,
        querytype: "tree",
        pageInfo: pageInfo
    };
    return ajaxMainTableData(postData)
        .then((res) => {
            if (res.success) {
                if (!res.data) {
                    res.data = {
                        'disputedlist': {
                            rows: []
                        }
                    };
                }
                let allpks = res.data['disputedlist'].allpks;
                handleAllpks.set(allpks);
                let pks = res.data['disputedlist'].rows[0] && res.data['disputedlist'].rows[0].values.pk_workdispute.value;
                handlePK.set(pks);
                this.props.editTable.setTableData('disputedlist', {rows: res.data['disputedlist'].rows});
                updateButtonStatus.call(this);
            }
        });
}
